#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
//声明结构体
typedef struct _point{
    int x, y;
    _point(int a, int b){
        x = a;
        y = b;
    }
}point;
//运算符重载，输入自定义结构体信息
ostream &operator<<(ostream& out, const point& p){
    out<<"("<<p.x<<","<<p.y<<")";
    return out;
}
bool my_less(int a, int b) {
    return a < b;
}
bool my_greater(int a, int b){
    return a > b;
}
//结构体自定义比较规则
bool comp(point p1, point p2){
    return p1.x == p2.x ? p1.y < p2.y : p1.x < p2.x;
}
int main(){
    vector<int> a = {3, 7, 2, 5, 6, 8, 5, 4};
    sort(a.begin(), a.end());   //默认从小到大

    //使用系统定义的比较函数排序
    sort(a.begin(), a.end(), less<int>());
    sort(a.begin(), a.end(), greater<int>());
    sort(a.begin(), a.end(), greater_equal<int>());
    sort(a.begin(), a.end(), less_equal<int>());
    //自定义的比较函数
    sort(a.begin(), a.end(), my_less);
    sort(a.begin(), a.end(), my_greater);

    sort(a.begin(), a.begin() + 4, my_greater);//sort(left, right) [left,right)
    for(auto it = a.begin(); it != a.end(); it++){
        cout<<*it<<" ";
    }
    cout<<endl;

    //自定义的结构体排序
    vector<point> points;
    points.push_back(point(1, 2));
    points.push_back(point(1, 1));
    points.push_back(point(2, 2));
    sort(points.begin(), points.end(), comp);
    for(auto it = points.begin(); it != points.end(); it++){
        cout<<*it<<" ";
    }
    
    return 0;
}
